﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Specialized;
using System.Data;

public partial class search : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnok_Click(object sender, EventArgs e)
    {

        if (IsPostBack)
        {
            btnok.Enabled = false;

            NameValueCollection args = Request.Form;
            if (args != null)
            {
                string strSerial = args["queryCode"].Trim();
                string strpasswd = args["queryPassword"].Trim();

                string strsql = string.Format("select * from [pollution] where [p_serial] = '{0}' and [p_passwd] = '{1}'",
                                                strSerial, strpasswd);
                ManageData md = new ManageData(util.DATACONNECTION);
                if (md != null)
                {
                    DataSet ds = md.ExecDS(strsql);
                    if (ds!= null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        QueryResult.Text = GetQueryResult(ds.Tables[0].Rows[0]);
                    }
                    else
                    {
                        QueryResult.Text = "<h1>没有查询到相关记录!</h1>";
                    }
                }


            }

            btnok.Enabled = true;
        
        }

    }

    private string GetMgrShow(string nId)
    {
        string strret = string.Empty;
        string sql = string.Format("SELECT  [u_show] FROM  [userinfo] WHERE [u_id] = '{0}'", nId);

        ManageData md = new ManageData(util.DATACONNECTION);
        if (md != null)
        {
            DataSet ds = md.ExecDS(sql);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
               strret = ds.Tables[0].Rows[0]["u_show"].ToString();
            }
            
        }
        return strret;

    }

    private string GetCoResult(string strType)
    {
        string strRet = string.Empty;

        switch (strType.Trim())
        {
            case "0":
                strRet = "处理中";
                break;
            case "1":
                strRet = "处理完成";
                break;
            default:
                break;
        }       

        return strRet;

    }

    private string GetQueryResult(DataRow r)
    {
        string ret = string.Empty;

        ret = "<table class='title-font' border='0' cellspacing='0' cellpadding='2' width='99%' bgcolor='#e6e6e6'><tr><td width='40%'>";

        ret += string.Format("<img src='./upload/{0}' width='100%'/> </td><td width='50%' align='left'><table width='100%' border='0'>",
            r["p_img"]);

        ret += GetInfo("污染源名称", r["p_name"].ToString());
        ret += GetInfo("举报人", r["p_rname"].ToString());
        ret += GetInfo("举报时间", r["p_ctdt"].ToString());

        ret += GetInfo("当前处理单位", GetMgrShow(r["u_id"].ToString()));

        ret += GetInfo("处理结果", GetCoResult(r["p_state"].ToString()));
        ret += GetInfo("查看动向", "查看动向中....");


        ret += "</table></td></tr></table>";


        return ret;
    }

    private string GetInfo(string strName, string strValue)
    {
        string strret = string.Empty;

        strret += "<tr><td class='biaoge-font' height='25' width='30%' colspan='2 style='border-right-style: solid; border-right-width: thin; border-right-color: #008080' > ";        
        strret += strName;
        strret += "</td><td class='biaoge-font' height='25' colspan='2'>";
        strret += strValue;
        strret += "</td></tr>";

        return strret;
    }
}
